//
//  LGHttpTool.m
//  微博
//
//  Created by MS on 15-12-8.
//  Copyright (c) 2015年 MS. All rights reserved.
//

#import "LGHttpTool.h"
#import "AFNetworking.h"


@implementation LGHttpTool

+ (void)GET:(NSString *)URLString
 parameters:(id)parameters
    success:(void (^)( id responseObject))success
    failure:(void (^)( NSError *error))failure
{
    AFHTTPSessionManager * manager = [AFHTTPSessionManager manager];
    
    [manager GET:URLString parameters:parameters success:^(NSURLSessionDataTask *task, id responseObject) {
        success(responseObject);
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        failure(error);
    }];
    
}

+ (void)POST:(NSString *)URLString
  parameters:(id)parameters
     success:(void (^)( id responseObject))success
     failure:(void (^)( NSError *error))failure
{
    AFHTTPSessionManager * manager = [AFHTTPSessionManager manager];
    
    [manager POST:URLString parameters:parameters success:^(NSURLSessionDataTask *task, id responseObject) {
        
        success(responseObject);
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        failure(error);
    }];
}

+(void)Upload:(NSString *)URLString
   parameters:(id)parameters uploadParama:(LGUploadParama *)uploadParama
      success:(void (^)())success
      failure:(void (^)( NSError *error))failure
{
    
    AFHTTPSessionManager * manager = [AFHTTPSessionManager manager];
    
    [manager POST:URLString parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        
     
        [formData appendPartWithFileData:uploadParama.data name:uploadParama.name fileName:uploadParama.fileName mimeType:uploadParama.mimeType];
      
        
        
        
    } success:^(NSURLSessionDataTask *task, id responseObject) {
        if (success) {
            success();
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
    
    
}
@end
